package com.tledu.meeting_info.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.meeting_info.domain.MeetingInfo;
import com.tledu.meeting_info.domain.dto.MeetingUserDto;
import com.tledu.meeting_info.service.IMeetingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会议列表Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/meeting_info/info")
public class MeetingInfoController extends BaseController
{
    @Autowired
    private IMeetingInfoService meetingInfoService;

    /**
     * 查询会议列表列表
     */
    @PreAuthorize("@ss.hasPermi('meeting_info:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeetingInfo meetingInfo)
    {
        startPage();
        List<MeetingInfo> list = meetingInfoService.selectMeetingInfoList(meetingInfo);
        return getDataTable(list);
    }

    /**
     * 导出会议列表列表
     */
    @PreAuthorize("@ss.hasPermi('meeting_info:info:export')")
    @Log(title = "会议列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingInfo meetingInfo)
    {
        List<MeetingInfo> list = meetingInfoService.selectMeetingInfoList(meetingInfo);
        ExcelUtil<MeetingInfo> util = new ExcelUtil<MeetingInfo>(MeetingInfo.class);
        util.exportExcel(response, list, "会议列表数据");
    }

    /**
     * 获取会议列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('meeting_info:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meetingInfoService.selectMeetingInfoById(id));
    }

    /**
     * 新增会议列表
     */
    @PreAuthorize("@ss.hasPermi('meeting_info:info:add')")
    @Log(title = "会议列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingUserDto meetingUserDto)
    {
        return toAjax(meetingInfoService.insertMeetingInfo(meetingUserDto));
    }

    /**
     * 修改会议列表
     */
    @PreAuthorize("@ss.hasPermi('meeting_info:info:edit')")
    @Log(title = "会议列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingInfo meetingInfo)
    {
        return toAjax(meetingInfoService.updateMeetingInfo(meetingInfo));
    }

    // 新增会议纪要
    @PutMapping("/summary/{id}")
    public AjaxResult addSummary(@RequestBody MeetingInfo meetingInfo,@PathVariable Long id) {
        int row = meetingInfoService.updateSummary(meetingInfo, id);
        return toAjax(row);
    }

    /**
     * 删除会议列表
     */
    @PreAuthorize("@ss.hasPermi('meeting_info:info:remove')")
    @Log(title = "会议列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meetingInfoService.updateMeetingInfoByIds(ids));
    }

    // 查看按钮
    @GetMapping("/search/{id}")
    public AjaxResult selectInfo(@PathVariable Long id) {
        MeetingUserDto meetingUserDto = meetingInfoService.selectMeetingInfoById(id);
        return AjaxResult.success(meetingUserDto);
    }

    //取消按钮
    @PutMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable Long id) {
        return toAjax(meetingInfoService.updateCancel(id));
    }

    // 开始按钮
    @PutMapping("/start/{id}")
    public AjaxResult start(@PathVariable Long id) {
        return toAjax(meetingInfoService.updateStart(id));
    }

    // 结束按钮
    @PutMapping("/end/{id}")
    public AjaxResult end(@PathVariable Long id) {
        meetingInfoService.updateEnd(id);
        return AjaxResult.success("结束成功");
    }

    // 新增会议纪要
//    @PostMapping
//    public AjaxResult minutes(@RequestBody MeetingInfo meetingInfo) {
//        return toAjax(meetingInfoService.addMinutes(meetingInfo));
//    }

}
